home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 001 / amigademo / amigademo.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  15KB  |  551 lines

  1. /*
  2.  * Article 2386 of net.sources:
  3.  * ion: version B 2.10.2 9/17/84 chuqui version 1.9 3/12/85; site unisoft.UUCP
  4.  * Posting-Version: version B 2.10.2 9/17/84; site cirl.UUCP
  5.  * Path: unisoft!dual!qantel!hplabs!tektronix!uw-beaver!cornell!vax135!houxm!mhuxt!mhuxr!ulysses!allegra!mit-eddie!think!cirl!gary
  6.  * From: gary@cirl.UUCP (Gary Girzon)
  7.  * Newsgroups: net.sources
  8.  * Subject: amigademo.c
  9.  * Message-ID: <224@cirl.UUCP>
  10.  * Date: 31 Oct 85 15:14:27 GMT
  11.  * Date-Received: 5 Nov 85 06:45:37 GMT
  12.  * Distribution: net
  13.  * Organization: Cochlear Implant Res. Lab, Boston, MA
  14.  * Lines: 533
  15.  * 
  16.  * The following is a graphics benchmark for the Commodore Amiga.
  17.  * It performs several graphics and Intuition ( Amiga's user interface )
  18.  * tasks. Some of the tests take some time, so be patient! There is a
  19.  * nice punch at the end.
  20.  * 
  21.  * Here are the results: ( ran as 1> amigademo > raw:file )
  22.  * 
  23.  *  Doing point test in a full-screen window
  24.  * Write pixel 640*200 took 31.5   Readpixel   640*200 took 23.1
  25.  * Move        640*200 took 6.8    Control     640*200 took 0.9
  26.  * Now doing point test directly to screen rastport
  27.  * Write pixel 640*200 took 23.7   Readpixel   640*200 took 15.4
  28.  * Move        640*200 took 6.8    Control     640*200 took 0.9
  29.  * Block clear blitter 1:6.9 CPU 20.0
  30.  * Block test in a full-screen window
  31.  * Set 32K 10.2 Copy 14.7 Complement 14.7
  32.  * Block test directly to screen rastport
  33.  * Set 32K 10.1 Copy 14.4 Complement 14.3
  34.  * Line test in window
  35.  * Offset 0 result:10.5
  36.  * Offset 1 result:10.6
  37.  * Offset 20 result:10.5
  38.  * Offset 100 result:10.4
  39.  * Window Benchmark #1 took 30.9
  40.  * Window Benchmark #2 took 0.1
  41.  * 
  42.  * 
  43.  *
  44.  *
  45.  * amiga/tutorial #88, from cheath, 13531 chars, Sat Oct 26 21:49:20 1985
  46.  *
  47.  * amigademo.c
  48.  *   Contains some example code for graphics and I/O,
  49.  * organized as simple benchmarks.  This is NOT the
  50.  * final vesion of these tests; it will be posted at a
  51.  * later date.
  52.  *
  53.  *             Copyright 1985 by MicroSmiths.
  54.  *   Permission is granted to use this code as an example for
  55.  * personal or commercial use.  If you use these as a benchmark
  56.  *   for publication, please credit MicroSmiths as the origin.
  57.  *
  58.  */
  59.  
  60. #include "exec/types.h"
  61. #include "exec/devices.h"
  62. #include "intuition/intuition.h"
  63.  
  64.  
  65. #include "exec/memory.h"      /* Need for AllocMem */
  66.  
  67. #define INTUITION_REV   29
  68. #define GRAPHICS_REV    29
  69.  
  70. #define WDTH 640   /* For a 640 * 200 , 16 color display   */
  71. #define HGHT 200
  72. #define DPTH 2
  73.  
  74. #define VIEW_MODE HIRES /* Set this for a 640 screen  */
  75.  
  76. #define NL NULL
  77.  
  78. #define VID MEMF_CHIP | MEMF_CLEAR     /* For allocating blitter-ram   */
  79.  
  80. /************************************************************************/
  81. /* These structures are included to avoid compile-time warnings.        */
  82. /* This is safe UNLESS YOU DECLARE A STRUCTURE THAT REQUIRES THEM.      */
  83. /************************************************************************/
  84.  
  85. struct CopList  { int fake; };   /* graphics/copper.h  */
  86. struct UCopList { int fake; };
  87. struct cprlist  { int fake; };
  88. struct Region   { int fake; };   /* graphics/regions.h  */
  89. struct VSprite  { int fake; };   /* graphics/gels.h     */
  90. struct collTable {int fake; };
  91. struct KeyMap   { int fake; };
  92.    
  93. /* These librarie handles are needed. No need to include a file ferem.. */
  94. struct GfxBase       { int fake; } *GfxBase;
  95. struct IntuitionBase *IntuitionBase;
  96.  
  97. WORD  *t_rast;      /* Temporary raster from AllocMem   */
  98. WORD   *area_buf;   /* Area used for AreaInfo   */
  99.  
  100. /****    Variables Initialized by init_generic()  **********/
  101. struct Screen *Screen;
  102. struct Window *Window;
  103. struct RastPort *pRp;   /* Graphics rendering area */
  104. struct MsgPort  *pUp;   /* Input message port   */
  105.  
  106. struct ViewPort *pVp;
  107.  
  108. struct timer {          /* Timer struct used to record times   */
  109.    int seconds,micros;
  110.    };
  111.  
  112. /******************************************************
  113. * Alright already, here's the stuff                   */
  114. main()
  115. {
  116. struct IntuiMessage *imsg;
  117.  
  118. init_generic();
  119.  
  120. printf("Doing point test in a full-screen window\n");
  121. point_test(pRp);     /* First try with the 'window' rastport   */
  122.  
  123. printf("Now doing point test directly to screen rastport\n");
  124. point_test(&Screen->RastPort); /* Next try the 'screen' rastport   */
  125.  
  126.  
  127. clear_test();     /* Does block clear of 32Kbytes  */
  128.  
  129. printf("Block test in a full-screen window\n");
  130. block_test(pRp);
  131.  
  132. printf("Block test directly to screen rastport\n");
  133. block_test(&Screen->RastPort);
  134.  
  135. printf("Line test in window\n");
  136. line_test(pRp);
  137.  
  138. window_test();
  139.  
  140. SetWindowTitles(Window,"Click Close to Quit...",NL);
  141.  
  142. SetDrMd(pRp,COMPLEMENT);
  143. FOREVER {
  144.    Draw(pRp,2+rand()%(WDTH-4),9+rand()%(HGHT-11));
  145.    if ( imsg = (struct IntuiMessage *)GetMsg(pUp) ) {
  146.       if ( imsg->Class == CLOSEWINDOW ) {
  147.  
  148.          close_generic();
  149.          }
  150.       SetRGB4(pVp,rand()&3,rand(),rand(),rand());
  151.       ReplyMsg(imsg);
  152.       }
  153.    }
  154. }
  155.  
  156.  
  157. /* Used to open the test Window   */
  158. struct NewWindow TstWindow = {
  159.    0,0,WDTH,HGHT, /* LeftEdge,TopEdge,Width,Height */
  160.    8,9,           /* DetailPen,BlockPen     */
  161.    NL,
  162.    SMART_REFRESH | ACTIVATE, /*Flags*/
  163.    NL,NL,"Test",   /* FirstGadget, CheckMark, Title  */
  164.    NL,         /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  165.    NL,         /* BitMap    */
  166.    100,60,32767,32767, /* MinW, MinH, MaxW, MaxH */
  167.    CUSTOMSCREEN };     /* Type   */
  168.  
  169.  
  170.  
  171. /***************************************************************
  172. * window_test()
  173. *     This test opens up a window 100 times. The window is
  174. * a full-screen WDTH*HGHT * 4 BitPlane display.
  175. *     Next, it does the same test but instead just does window-
  176. * to-front, window-to-back 100 times.
  177. ***************************************************************/
  178. window_test()
  179. {
  180. register int i;
  181. register struct Window *tst_window;
  182. struct timer start,finish ,t2start,t2finish;
  183.  
  184. TstWindow.Screen = Screen;
  185.  
  186. CurrentTime(&start.seconds,&start.micros);
  187. for ( i=0 ; i<100 ; i++) {
  188.    if ( ! (tst_window=(struct Window *)OpenWindow(&TstWindow)) ) {
  189.  
  190.       printf("Error Openeing Window, aborted!\n");
  191.       close_generic();
  192.       }
  193.    CloseWindow(tst_window);
  194.    }
  195. CurrentTime(&finish.seconds,&finish.micros);
  196. printf("Window Benchmark #1 took "); delta(&finish,&start);
  197. printf("\n");
  198.  
  199. /* Now do second test... Just WindowToFront, WindowToBack   */
  200. tst_window = (struct Window *)OpenWindow(&TstWindow);
  201.  
  202. CurrentTime(&t2start.seconds,&t2start.micros);
  203. for ( i=0; i<100 ; i++) {
  204.    WindowToBack(tst_window);
  205.    WindowToFront(tst_window);
  206.    }
  207. CloseWindow(tst_window);
  208. CurrentTime(&t2finish.seconds,&t2finish.micros);
  209.  
  210.  
  211. printf("Window Benchmark #2 took "); delta(&t2finish,&t2start);
  212. printf("\n");
  213. }
  214.  
  215.  
  216.  
  217.  
  218. /**************************************************************
  219. * point_test(rastport)
  220. *     This routine tests the Read/Write/Move pixel functions
  221. ***************************************************************/
  222. point_test(rastport)
  223. struct RastPort *rastport;
  224. {
  225. register struct RastPort *fRp;
  226. register int x,y;
  227.  
  228. struct timer write,read,move,control, start;
  229.  
  230.    fRp = rastport;
  231.  
  232.  
  233.    CurrentTime(&start.seconds,&start.micros);
  234.    for (y=0;y<HGHT;y++) {
  235.       SetAPen(fRp,y&15);
  236.       for (x=0;x<WDTH; x++)
  237.          WritePixel(fRp,x,y);
  238.       }
  239.    CurrentTime(&write.seconds,&write.micros);
  240.  
  241.    for (y=0;y<HGHT;y++) {
  242.       for (x=0;x<WDTH; x++)
  243.          ReadPixel(fRp,x,y);
  244.       }
  245.    CurrentTime(&read.seconds,&read.micros);
  246.  
  247.    for (y=0;y<HGHT;y++) {
  248.       for (x=0;x<WDTH; x++)
  249.          Move(pRp,x,y);
  250.       }
  251.    CurrentTime(&move.seconds,&move.micros);
  252.  
  253.  
  254.    for (y=0;y<HGHT;y++)
  255.       for (x=0;x<WDTH; x++)
  256.          ;
  257.    CurrentTime(&control.seconds,&control.micros);
  258.    printf("Write pixel 640*200 took "); delta(&write,&start);
  259.    printf("   Readpixel   640*200 took "); delta(&read,&write);
  260.    printf("\nMove        640*200 took "); delta(&move,&read);
  261.    printf("    Control     640*200 took "); delta(&control,&move);
  262.    printf("\n");
  263. }
  264.  
  265.  
  266. /***********************************************************
  267. *  block_test
  268. *     Does block copy, set block to value, block complement.
  269. * These are all done by "applications" functions supplied in the
  270. * Amiga graphics library.  It may be possible to speed these up a
  271. * bit if you are not rendering in a rastport, using direct blitter
  272. * manipulations.
  273.  
  274. *****************************************************************/
  275.  
  276. block_test(rastport)
  277. struct RastPort *rastport;
  278. {
  279. struct timer start1,finish1,finish2,finish3;
  280.  
  281. register int i;
  282.  
  283. #define COPY 0xc0    /* These are blitter minterms */
  284. #define XOR  0x50
  285.  
  286.    CurrentTime(&start1.seconds,&start1.micros);
  287.  
  288.    for ( i=0; i<500; i++ )
  289.       SetRast(rastport,i&3);
  290.  
  291.    CurrentTime(&finish1.seconds,&finish1.micros);
  292.  
  293.    for ( i=0; i<500; i++)
  294.  
  295.       ClipBlit(rastport,0,0,rastport,0,0,WDTH,HGHT,COPY);
  296.  
  297.    CurrentTime(&finish2.seconds,&finish2.micros);
  298.  
  299.    for ( i=0; i<500; i++)
  300.       ClipBlit(rastport,0,0,rastport,0,0,WDTH,HGHT,COPY);
  301.  
  302.    CurrentTime(&finish3.seconds,&finish3.micros);
  303.  
  304.    printf("Set 32K "); delta(&finish1,&start1);
  305.    printf(" Copy "); delta(&finish2,&finish1);
  306.    printf(" Complement "); delta(&finish3,&finish2);
  307.    printf("\n");
  308. }
  309.  
  310. /*****************************************************************
  311. * clear_test()
  312. *     This test clears a block of memory two ways:
  313. * First, using an applications blitter-clear call;
  314. * Then using a somewhat optimized long-word clear using the
  315.  
  316. * 68000.  
  317. *****************************************************************/
  318. clear_test()
  319. {
  320. struct timer start1,finish1,finish2;
  321.  
  322. register WORD *mem_ptr;
  323. register LONG *mp2;
  324.  
  325. register int i,j;
  326.  
  327.    if ( ! (mem_ptr = (WORD *) AllocMem(32000,VID)) ) {
  328.       printf("Can't get mem for clear test\n");
  329.       close_generic();
  330.       }
  331.  
  332.    CurrentTime(&start1.seconds,&start1.micros);
  333.  
  334.    /* Use the blitter alone to clear mem  */
  335.    for ( i = 0; i < 499 ; i++)
  336.  
  337.       BltClear(mem_ptr,32000,0); /* flags are 'Don't Wait'  */
  338.    WaitBlit();    /* Wait for the above to finish...  */
  339.  
  340.    CurrentTime(&finish1.seconds,&finish1.micros);
  341.  
  342.    /* Use the CPU alone to clear mem   */
  343.    for ( i=0; i<500 ; i++) {
  344.       mp2 = (LONG *)mem_ptr;
  345.       for ( j = 0; j < 2000 ; j++) {
  346.          *mp2++ = NL;
  347.          *mp2++ = NL;
  348.          *mp2++ = NL;
  349.          *mp2++ = NL;
  350.          }
  351.       }
  352.  
  353.    CurrentTime(&finish2.seconds,&finish2.micros);
  354.  
  355.    printf("Block clear blitter 1:"); delta(&finish1,&start1);
  356.    printf(" CPU "); delta(&finish2,&finish1);
  357.  
  358.    printf("\n");
  359.    FreeMem(mem_ptr,32000);
  360. }
  361.  
  362. line_test(rastport)
  363. struct RastPort *rastport;
  364. {
  365.  
  366.    line_sub(rastport,0);
  367.    line_sub(rastport,1);
  368.    line_sub(rastport,20);
  369.    line_sub(rastport,100);
  370. }
  371.  
  372. /************************************************************
  373. * line_sub(offset)
  374. *     This routine was borrowed from bwebster, originating from
  375. * a guy in Switzerland named Fons Rademakers of CERNS, who
  376. * designed the test for comparing Mac and Apollos           */
  377. line_sub(rastport,offset)
  378.  
  379. int offset;
  380. struct RastPort *rastport;
  381. {
  382. register int x1,y1,x2,y2,i,j;
  383. register struct RastPort *fastrp;
  384.  
  385. struct timer start,finish;
  386.  
  387. fastrp = rastport;
  388.  
  389. CurrentTime(&start.seconds,&start.micros);
  390.  
  391. x1 = 150 - offset;
  392. y1 = 0;
  393. x2 = 150+offset;
  394. y2 = 199;
  395.  
  396. for ( i=0; i<20; i++) {
  397.    SetAPen(fastrp,i&3);
  398.    for ( j=0; j < 200; j++) {
  399.  
  400.       Move(fastrp,x1++,y1);
  401.       Draw(fastrp,x2++,y2);
  402.       }
  403.    SetAPen(fastrp,(~i)&3);
  404.    for ( j=0; j<200; j++) {
  405.       Move(fastrp,x1--,y1);
  406.       Draw(fastrp,x2--,y2);
  407.       }
  408.    }
  409. CurrentTime(&finish.seconds,&finish.micros);
  410. printf("Offset %d result:",offset); delta(&finish,&start);
  411. printf("\n");
  412. }
  413.  
  414.  
  415. /***************************************************
  416. * delta()
  417. *     This little cluge calculates the delta-time
  418. * and prints it, along with a '\n'                */
  419. delta(finish,start)
  420.  
  421. struct timer *finish,*start;
  422. {
  423. int dsec,dmic;
  424.  
  425.    dmic = finish->micros - start->micros;
  426.    dsec = finish->seconds - start->seconds;
  427.  
  428.    if (dmic < 0) {
  429.       dmic += 1000000;
  430.       dsec--;
  431.       }
  432.    printf("%d.%d",dsec,dmic/100000);
  433. }
  434.  
  435.  
  436.  
  437.  
  438.  
  439. /************************************************************************/
  440. /* Many of the Amiga 'C' language structures are most efficiently set   */
  441.  
  442. /* up by initializing the values with the declarations         */
  443. /************************************************************************/
  444.  
  445. /* Font Descriptor   */
  446. struct TextAttr MyFont = {"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT };
  447.  
  448. /* Used to open a Screen   */
  449. struct NewScreen NewScreen = {
  450.    0,0,WDTH,HGHT,DPTH,  /* Left,Top,Width,Height,Depth    */
  451.    7,8,VIEW_MODE,            /* DetailPen, BlockPen, ViewModes */
  452.    CUSTOMSCREEN,&MyFont,/* Type, Font  */
  453.    (UBYTE *)"Expletive Deletion",  /* Title       */
  454.    NL,NL };       /* Gadgets, BitMap  */
  455.  
  456. /* Used to open a Window   */
  457. struct NewWindow NewWindow = {
  458.    0,0,WDTH,HGHT, /* LeftEdge,TopEdge,Width,Height */
  459.    8,9,           /* DetailPen,BlockPen     */
  460.    CLOSEWINDOW | MOUSEMOVE,
  461.    WINDOWCLOSE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH |
  462.  
  463.       ACTIVATE | REPORTMOUSE, /*Flags*/
  464.    NL,NL,"Main Window",   /* FirstGadget, CheckMark, Title  */
  465.    NL,         /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  466.    NL,         /* BitMap    */
  467.    100,60,32767,32767, /* MinW, MinH, MaxW, MaxH */
  468.    CUSTOMSCREEN };     /* Type   */
  469.  
  470.  
  471. /* These items are used as temp buffers for fill etc  */
  472. #define AREA_ENTS 400   /* Number of areabuffer entries, area_buf */
  473. #define AREASIZ AREA_ENTS*5   /* Space for AreaInfo   */
  474.  
  475. struct AreaInfo   area_info;
  476. struct TmpRas     tmp_ras;
  477.  
  478.  
  479.  
  480. /****************************************************************
  481. * init_generic()
  482. *
  483.  
  484. *     Opens Screen and full-sized Window for ****** program.
  485. *     Sets up TmpRas for draw and flood-fill
  486. *     Allocates and initializes various buffer areas...
  487. *
  488. *     Initializes handles Screen,Window,pRp
  489. *
  490. *  See also: close_generic()                                     */
  491. init_generic()
  492. {
  493.    if ( ! (IntuitionBase = (struct IntuitionBase *)
  494.      OpenLibrary("intuition.library",INTUITION_REV)) ||
  495.       ! (GfxBase = (struct GfxBase *)
  496.      OpenLibrary("graphics.library",GRAPHICS_REV))  ||
  497.       ! (Screen =(struct Screen *)OpenScreen(&NewScreen)) ) {
  498.      printf("Wow this shouldn't happen!!!\n");
  499.           exit(101);
  500.           }
  501.  
  502.    NewWindow.Screen = Screen;   /* NEED TO SET SCREEN!!! */
  503.  
  504.  
  505.    if ( ! (Window =(struct Window *)OpenWindow(&NewWindow))) {
  506.       printf("Sombody stole your memory!");
  507.       exit(102);
  508.       }
  509.  
  510.    pRp = Window->RPort;    /* Get E-Z acess to handles  */
  511.    pUp = Window->UserPort;
  512.    pVp = (struct ViewPort *)ViewPortAddress(Window);
  513.  
  514.    /* Allocate major buffer entries */
  515.    t_rast   = (WORD *) AllocMem(RASSIZE(WDTH,HGHT), VID);
  516.    area_buf = (WORD *) AllocMem(2000,VID);
  517.  
  518.    if ( ! t_rast || ! area_buf ) {
  519.       printf("Out of memory\n");
  520.       exit(103);
  521.       }
  522.  
  523.    /* Initialize rastport temp buffers */
  524.    InitArea(&area_info,area_buf,AREA_ENTS);
  525.  
  526.    pRp->AreaInfo = &area_info;
  527.  
  528.    tmp_ras.RasPtr = (BYTE *)t_rast;
  529.    tmp_ras.Size = RASSIZE(WDTH,HGHT);
  530.    pRp->TmpRas = &tmp_ras;
  531. }
  532.  
  533.  
  534. /*************************************************
  535. * close_generic
  536. *
  537. *  Returns all resources gotten by init_generic
  538. *************************************************/
  539. close_generic()
  540. {
  541.    FreeMem(t_rast,RASSIZE(WDTH,HGHT));
  542.    FreeMem(area_buf,2000);
  543.  
  544.    CloseWindow(Window);
  545.    CloseScreen(Screen);
  546.  
  547.    exit();
  548. }
  549.  
  550.  
  551.